#!/bin/sh
# https://github.com/shyiko/ktlint pre-commit hook
# check if ktlint is installed
type ktlint >/dev/null 2>&1
if [ $? -ne 0 ];then
  echo "please install ktlint first, visit https://github.com/pinterest/ktlint#installation"
  exit 1
fi
src_file=$(dirname $(dirname $(pwd)))
editorconfig_file="${src_file}/.editorconfig"
if [ -f "$editorconfig_file" ];then
   git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint --editorconfig=editorconfig_file --relative .
else
   git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint --relative .
fi
if [ $? -ne 0 ]; then exit 1; fi
